<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const obj = {
            a: 1,
            b: 'hello world',
            c: {
                msg: 'hi',
            },
            d: [1, 2],
            e: [
                {
                    a: 1,
                    b: 2,
                },
                'abc',
                123,
            ],
        };
        function deepClone (x) {
            const res = new x.constructor();
            for (const key in x) {
                // 当前项的值
                const value = x[key];
                // 判断是否是对象或数组
                if (value instanceof Object) {
                    res[key] = deepClone(value);
                } else { // 基础数据类型
                    res[key] = value;
                }
            }
            return res;
        }
        console.log(deepClone(obj));
        
    </script>
</body>
</html>